package com.lg.online_shop.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.lg.online_shop.entity.Orders;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface OrderMapper extends BaseMapper<Orders> {
//    根据 uid 获取订单列表
    @Select("select * from  orders where  u_id = #{uId}")
    List<Orders> selectOrderByUid(int uId);

//    将status 改成 2
    @Update("update orders set status = #{code} where id = #{id}")
    int updateOrderStatus(Long id, int code);

//    获取购买历史
    @Select("select * from orders where u_id = #{uId} and status = 1")
    List<Orders> selectBuyHistory(Long uId);

//    批量导入订单
    @Insert("insert into orders(g_name,orders.g_id,u_id,count,size_id,color_id,status,total_price,address_id) values(#{gName},#{gId},#{uId},#{count},#{sizeId},#{colorId},#{status},#{totalPrice},#{addressId})")
    int insertOrder(Orders orders);

//    获取status为1的数量
    @Select("select count(*) from orders where status = 1")
    Long selectCountWithPaid();

//    获取总营业额
    @Select("select sum(total_price) from orders where status = 1")
    double selectSalemoney();
}
